package com.cool.pojo;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.collections4.comparators.ComparatorChain;

import com.cool.mybatisplus.AgeConvertHandler;
import com.cool.util.StringUtil;
import com.github.liaochong.myexcel.core.annotation.ExcelColumn;
import com.github.liaochong.myexcel.core.annotation.ExcelModel;

import lombok.Data;
import lombok.ToString;

/**
 * 人物对象
 * 
 * @author bian
 * @date 2021-02-10
 */
@Data
@ToString
@ExcelModel(sheetName = "test")
public class Man {
    @ExcelColumn(title = "姓名", style = {"title->color:white", "title->text-align:center", "title->background-color:green;", "text-align:center"})
    private String name;

    @ExcelColumn(title = "年龄", style = {"title->color:white", "title->text-align:center", "title->background-color:green;", "text-align:center"},
        writeConverter = AgeConvertHandler.class)
    private int age;

    @ExcelColumn(title = "地址", style = {"title->color:white", "title->text-align:center", "title->background-color:green;", "text-align:center"})
    private String address;

    @ExcelColumn(title = "电话", style = {"title->color:white", "title->text-align:center", "title->background-color:green;", "text-align:center"})
    private String phone;

    @ExcelColumn(title = "时间", style = {"title->color:white", "title->text-align:center", "title->background-color:green;", "text-align:center"},
        format = "yyyy:MM:dd HH:mm:ss")
    private Long time;

    public static List<Man> getManList() {
        java.util.List<Man> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Man man = new Man();
            man.setAge(i);
            man.setName(StringUtil.randomName(true, 3));
            man.setAddress(null);
            man.setPhone("12345" + i);
            man.setTime(1626185408256L);
            list.add(man);
        }
        return list;
    }

    public static void main(String[] args) {
        List<Man> manList = Man.getManList();
        ComparatorChain<Man> multiSort = new ComparatorChain<>();
        multiSort.addComparator(new BeanComparator<>("address", Comparator.nullsLast(String::compareTo)));
        multiSort.addComparator(new BeanComparator<>("name", Comparator.nullsLast(String::compareTo)));
        multiSort.addComparator(new BeanComparator<>("age", Comparator.nullsLast(String::compareTo)), true);
        manList.sort(multiSort);
        System.out.println(manList);
        Date date = new Date();
        long time = date.getTime();
        System.out.println(time);
    }
}
